package edu.etu.sob.resource;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
import javax.xml.bind.JAXBContext;

import com.hp.hpl.jena.graph.MyNode;
import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.jersey.api.json.JSONJAXBContext;

import edu.etu.sob.model.impl.LiteralRestriction;
import edu.etu.sob.model.impl.OntClassDesc;
import edu.etu.sob.model.impl.OntResourceDesc;
import edu.etu.sob.model.impl.RDFTripleDesc;
import edu.etu.sob.model.impl.ResourceRestriction;

@Provider
@Produces(MediaType.APPLICATION_JSON)
public class JAXBJSONContextResolver implements ContextResolver<JAXBContext> {

	private JAXBContext context;
	
	private final Set<Class> types;
	private Class[] cTypes = {MyNode.class, RDFTripleDesc.class, OntClassDesc.class, OntResourceDesc.class, ResourceRestriction.class, LiteralRestriction.class};

    public JAXBJSONContextResolver() throws Exception {
    	this.types = new HashSet(Arrays.asList(cTypes));
        context = new JSONJAXBContext(JSONConfiguration.mapped().rootUnwrapping(false).build(), cTypes);
    }
    
    @Override
    public JAXBContext getContext(Class<?> objectType) {
    	return (types.contains(objectType)) ? context : null;
    }


}
